package com.lmn.controller;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

/**
 * use = JsonTypeInfo.Id.NAME：使用逻辑类型名称来标识类型
 * property = "orderName"：定义JSON属性名，该属性将包含类型信息；也就是我们请求的body需要包含 "orderName" 字段，并且值是对应@JsonSubTypes.Type注解中的name值。
 * visible = true：类型信息属性（"orderName"）在JSON输出中可见
 */
@JsonTypeInfo(
        use = JsonTypeInfo.Id.NAME,
        include = JsonTypeInfo.As.PROPERTY,
        property = "orderName",
        visible = true
)

/**
 * @JsonSubTypes.Type：将逻辑名称映射到对应的Java类
 */
@JsonSubTypes(
        {
                @JsonSubTypes.Type(value = DiscountOrder.class, name = "discountOrder"),
                @JsonSubTypes.Type(value = RegularOrder.class, name = "regularOrder")
        }
)
public interface Order {
}


/**
 * public class Order {
 *
 *   @JsonTypeInfo(
 *     use = JsonTypeInfo.Id.NAME,
 *     include = JsonTypeInfo.As.EXTERNAL_PROPERTY,
 *     property = "type")
 *   @JsonSubTypes({
 *       @JsonSubTypes.Type(value = String.class, name = "string"),
 *       @JsonSubTypes.Type(value = Long.class, name = "long"),
 *       @JsonSubTypes.Type(value = Integer.class, name = "int")
 *   })
 *   protected Object value;
 * }
 */


/**
 * 127.0.0.1:8081/order
 *
 * {
 *     "orderName":"regularOrder"
 * }
 */
